#ifndef _SMTP_H_
#define _SMTP_H_

//TO_BE_EXPORTED

#ifdef SMTPLIBRARY_EXPORTS
	#define SMTPLIBRARY_API __declspec(dllexport)
#else
	#define SMTPLIBRARY_API __declspec(dllimport)
#endif

#include <winsock2.h>
#include <assert.h>
#include <vector>

const int DEFAULT_PROTOCOL = 0;
const int NO_FLAGS = 0;

namespace mail
{
	class Recipient;

	class SMTPLIBRARY_API Smtp  
	{
	public:

		Smtp();    
		virtual ~Smtp();

		//
		bool    ConnectServer(const char server[], const unsigned short port=NULL);
		bool    Disconnect();
		bool    GetConnectStatus();
		bool    Send();


		//Recipient
		const unsigned int    GetBCCRecipientCount();    
		const unsigned int    GetCCRecipientCount();
		const unsigned int    GetRecipientCount();
		
		bool    AddRecipient(const char email[], const char name[]="");
		bool    AddBCCRecipient(const char email[], const char name[]="");
		bool    AddCCRecipient(const char email[], const char name[]="");    


		//Get
		const unsigned int		GetSocket();
		const char*    const    GetLocalHostIp();
		const char*    const    GetLocalHostname();    
		const char*    const    GetMessageBody();    
		const char*    const    GetReplyTo();
		const char*    const    GetSenderEmail();
		const char*    const    GetSenderName();
		const char*    const    GetSubject();    
		const char*    const    GetXMailer();    

		//Set
		void  SetMessageBody(const char body[]);    
		void  SetSubject(const char subject[]);    
		void  SetSenderName(const char name[]);    
		void  SetSenderEmail(const char email[]);    
		void  SetReplyTo(const char replyto[]);    
		void  SetXMailer(const char xmailer[]);

	private:
		bool bCon;
		char m_cHostName[MAX_PATH];
		char* m_pcFromEmail;
		char* m_pcFromName;
		char* m_pcSubject;
		char* m_pcMsgBody;
		char* m_pcXMailer;
		char* m_pcReplyTo;
		char* m_pcIPAddr;    

		WSADATA wsaData;
		SOCKET hSocket;

		std::vector<Recipient*> Recipients;
		std::vector<Recipient*> CCRecipients;
		std::vector<Recipient*> BCCRecipients;    
    
		char*   _formatHeader();    
		bool    _formatMessage();
		SOCKET  _connectServerSocket(const char* server, const unsigned short port=NULL);
	};
}
#endif